import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

public class Leetcode3 {

    static Map<String, Integer> map;
    static List<String> list;

    static {
        map = new HashMap<>();
        list = new ArrayList<>();
        for (int i = 0; i < 1000000; i++) {
            map.put("a" + i, i);
            list.add("a" + i);
        }
    }

    public static void main(String[] args) {

    }

    public static int lengthOfLongestSubstring(String s) {
        if (s.length() == 1) {
            return 1;
        }

        int maxLength = 0;
        char[] characters = s.toCharArray();
        int left = 0;
        int right = 1;
        int n = s.length();
        while (right < n) {
            for (int i = left; i < right; i++) {
                if (characters[i] == characters[right]) {
                    left = i + 1;
                    break;
                }
            }
            right++;

            maxLength = Math.max(maxLength, right - left);
        }

        return maxLength;
    }
}
